/*
 * Copyright (C) 2007-2008 SlideMe client
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.slideme.android.manager.respoitory;

import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public final class DatabaseOpenHelper extends SQLiteOpenHelper {
    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.d("ContentBundleContentProvider", "Creating database for content bundle");
        StringBuffer sb = new StringBuffer();
        sb.append("CREATE TABLE content_bundle (");
        sb.append("_id INTEGER PRIMARY KEY,");
        sb.append("bundleId TEXT,");
        sb.append("displayName TEXT,");
        sb.append("contentURI TEXT,");
        sb.append("shortDescription TEXT,");
        sb.append("vendorName TEXT,");
        sb.append("price TEXT,");
        sb.append("longDescription TEXT,");
        sb.append("iconUri TEXT,");
        sb.append("iconFileUri TEXT,");
        sb.append("category TEXT,");
        sb.append("version TEXT,");
        sb.append("termsAndConditions TEXT,");
        sb.append("creationDate TEXT,");
        sb.append("isInstalled TEXT");//boolean        
        sb.append(");");
        db.execSQL(sb.toString());

        Log.d("InstalledBundleContentProvider-1", "Creating database for installed bundles");
        sb = new StringBuffer();
        sb.append("CREATE TABLE installed_bundle (");
        sb.append("_id INTEGER PRIMARY KEY,");
        sb.append("bundleId TEXT");
        sb.append(");");
        db.execSQL(sb.toString());

        sb = new StringBuffer();
        sb.append("CREATE TABLE settings_info (");
        sb.append("_id INTEGER PRIMARY KEY,");
        sb.append("serverURI TEXT");
        sb.append(");");
        db.execSQL(sb.toString());
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i("DatabaseOpenHelper", "Upgrading database: Old Version = " + oldVersion + ", New Version = " + newVersion);
        db.execSQL("DROP TABLE IF EXISTS content_bundle;");
        db.execSQL("DROP TABLE IF EXISTS installed_bundle;");
        db.execSQL("DROP TABLE IF EXISTS settings_info;");
        onCreate(db);
    }
}
